package com.card323.crpg;

import com.card323.crpg.battle.ActionPoint;
import com.card323.crpg.cmdhandler.MainCommandHandler;
import com.card323.crpg.effect.Effect;
import com.card323.crpg.item.HealthEffect;
import com.card323.crpg.item.ItemApple;
import com.card323.crpg.skill.*;

public class Engine implements Runnable {

	Hero _hero;
	MainCommandHandler _handler;

	public Engine(String email, String client_type) {
		_hero = PlayerManager.getInstance().init_player(email,client_type);
		_handler=new MainCommandHandler(_hero);
	}

	

	public void run() {

		cmd_test();
		//io_test();
		//battle_test();
	}

	private void cmd_test() {
		set_hero1(_hero);

		_hero.send_message("游戏初始化完毕");
		_hero.send_message("*输入?以显示游戏帮助");
		while (true) {
			
			String msg = _hero.get_message();
			_handler.handle(msg);
		}
	}

	private void set_hero1(Hero hero) {
		hero.set_name("card323");
		hero._base_attack = 2;
		hero._random_attack = 0;
		hero._random_attack_times = 2;
		hero.set_life(20);
		hero.set_current_life(20);
		hero._attack_speed = new ActionPoint(3,0,0,0,0,0);
		hero._email = "card323@gmail.com";
		hero.set_item(1,new ItemApple());
		hero.set_item(2,new ItemApple());
		hero.set_item(3,new ItemApple());
		hero.set_item(4,new ItemApple());
		hero._is_ai = false;
		
		Skill skill=new SelfTargetSkill();
		Effect active_effect=new HealthEffect(5);
		skill.add_effect(active_effect);
		skill.set_ap_cost(new ActionPoint(2,0,0,0,0,0));
		skill.set_name("包扎伤口");
		skill.set_info(" (2)回复自身5点生命");
		hero.add_skill("q",skill);
		

		hero.add_skill("w",new HealSkill());
		hero.add_skill("e",new WarRoarSkill());
		hero.add_skill("r",new HardWillSkill());
//		Skill passive_skill =new PassiveSkill(hero);
//		Effect effect=new HealthEffect(3);
//		Buff buff=new Buff();
//		buff.add_effect(effect);
//		passive_skill.add_buff(buff);
//		passive_skill.set_name("再生皮肤");
//		passive_skill.set_info(" (被动)每回合回复3点生命");
//		hero.add_skill("e",passive_skill);

	}

	@SuppressWarnings("unused")
	private void io_test() {
		boolean is_io_test = true;
		while (is_io_test) {
			_hero.send_message("say something");
			String msg = _hero.get_message();
			_hero.send_message("you said:" + msg);
		}

	}

}
